//
//  LFGoodsCell.m
//  LoveFruit
//
//  Created by Hannibal_zj on 16/9/23.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFGoodsCell.h"

@interface LFGoodsCell ()<UIActionSheetDelegate>

// 商品
@property (weak, nonatomic) IBOutlet UILabel *goodsNameLabel;
// 价格
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

// 库存
@property(nonatomic,assign)NSInteger store_nums;
// 减号按钮
@property (weak, nonatomic) IBOutlet UIButton *reduceButton;
// 加号按钮
@property (weak, nonatomic) IBOutlet UIButton *addButton;
// id
@property(nonatomic,copy)NSString *id;

@property (weak, nonatomic) IBOutlet UIImageView *shopImageView;

@end

@implementation LFGoodsCell


// 重写新鲜预订的数据set方法
-(void)setFreshOrderModel:(LFFreshOrdergoodsModel *)freshOrderModel {
    
    _freshOrderModel = freshOrderModel;
    
    self.goodsNameLabel.text = [self.goodsNameLabel.text stringByAppendingString:freshOrderModel.name];
    
    self.priceLabel.text = freshOrderModel.partner_price;
    
    self.quantityLabel.text =  [NSString stringWithFormat:@"%zd",self.freshOrderModel.alreadyBuyCount];
    
    self.store_nums = self.freshOrderModel.number;
     [self.shopImageView sd_setImageWithURL:[NSURL URLWithString:freshOrderModel.img]];
}



// 重写首页数据set方法
-(void)setHotSellerModel:(LFHotSellerModel *)hotSellerModel {
    
    _hotSellerModel = hotSellerModel;
    


        
        self.goodsNameLabel.text = hotSellerModel.name;
    
        self.priceLabel.text = hotSellerModel.price;
        
        self.quantityLabel.text =  [NSString stringWithFormat:@"%zd",self.hotSellerModel.ismix];
        
        self.store_nums = self.hotSellerModel.store_nums;

    
     [self.shopImageView sd_setImageWithURL:[NSURL URLWithString:hotSellerModel.img]];
    
    
}


// 减号按钮点击事件
- (IBAction)desBtnClick:(UIButton *)sender {

    NSLog(@"-----%zd",(self.quantityLabel.text).integerValue);
    NSInteger count = (self.quantityLabel.text).integerValue;
    
    count--;
    if (count >= 1) {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"des" object:nil userInfo:@{@"cellKey":self}];
    }
  
    
    if (count < 1) {
    
        [[NSNotificationCenter defaultCenter] postNotificationName:@"Deletegoods" object:nil userInfo:@{@"cellKey":self}];
    }
    
    self.quantityLabel.text = [NSString stringWithFormat:@"%zd",count];
}
// 加号按钮点击事件
- (IBAction)addBtnClick:(UIButton *)sender
{
    
    NSInteger count = (self.quantityLabel.text).integerValue;
    if (count >=  self.store_nums)
    {
        [SVProgressHUD showInfoWithStatus:@"货已不足"];
        
        return;
    }
    count++;
    
     
    self.quantityLabel.text = [NSString stringWithFormat:@"%zd",count];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"add" object:nil userInfo:@{@"cellKey":self}];
}


@end
